package keter.framework.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

public class PathUtil {
	/**
	* Logger for this class
	*/
	private static final Logger logger = LoggerFactory.getLogger(PathUtil.class);

	/**
	 * 获取当前jar/war包所在路径
	 * 用于从相对路径查找配置文件等
	 * @author gulixing@msn.com
	 * @date   2016年1月5日
	 */
	public static String getJarPath() {
		File file = new File("nonexist").getAbsoluteFile();
		try {
			return file.getParentFile().getCanonicalPath();
		} catch (IOException e) {
			logger.error("jar路径获取失败!",e);
		}
		throw new NullPointerException("jar路径获取失败!");
	}
	
	public static void main(String[] args) {
		System.out.println(getJarPath());
//	    com.jfinal.plugin.activerecord.dialect.Sqlite3Dialect
//		System.out.println(getClassPath(Unit.class));
	}
}
